var swiper = new Swiper('#home', {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    loop:true
});

$.fn.stab = function(){
    this.each((_, el) => {
        let $el = $(el)
        let $titles = $el.find('>.titles')
        let $view = $el.find('>.views>.view')
        let $title = $el.find('>.titles>.title')
        let len = $title.length
        let current = 0
        let old = 0
        let lock = false
        let autorun = $el.data('autorun')
        let tabhover = $el.data('tabhover')
        let slide = $el.data('slide')
        let changeTab = () => {
        if(!slide){
            $view.hide()
            $view.eq(current).show()
        }else{
            lock = true
            let $o = $view.eq(old)
            let $c = $view.eq(current)
            $o.addClass('after')
            $c.addClass('pre')
            $c.show()
            sleep(20).then(() => $c.removeClass('pre'))
            sleep(1000).then(() => {
            $o.hide()
            $o.removeClass('after')
            lock = false
            })
        }
        $title.removeClass('active')
        $title.eq(current).addClass('active')
        }
        let ev = e => {
            if(lock) return
        let $el = $(e.currentTarget)
        if($el.hasClass('active')) return
            old = current
            current = $title.index($el)
            changeTab()
        }
        $titles.on('click', '>.title', ev)
        if(tabhover){
            $titles.on('mouseenter', '>.title', ev)
        }
        if(autorun){
        setInterval(function(){
            if(lock) return
            old = current
            current++
            current >= len && (current = 0)
            changeTab()
        }, autorun)
        }
    })
}

$('.m-tab').stab()

